import configparser


class CustomConfigParser(configparser.ConfigParser):
    def __init__(self):
        super().__init__()

    def read_config(self, filename):
        """Read and parse config file.

        Args:
            param1 (str): Filename of config file.

        """
        super().read(filename, encoding='utf-8')

        d = dict(self._sections)
        # build and return dict from config file
        for k in d:

            d[k] = dict(self._defaults, **d[k])
            for j in d[k]:
                # Interpret line breaks as individual elemtents, i.e. for passing several urls
                if '\n' in d[k][j]:
                    d[k][j] = [item for item in d[k][j].strip().split('\n')]
                d[k].pop('__name__', None)
        return d


def getConfigFromConfigfile(file):
    configParser = CustomConfigParser()
    return configParser.read_config(file)


if __name__ == '__main__':
    from pprint import pprint
    file_path = '/Users/liuyang/Desktop/00_刘阳/100_saved_codes/04_QA_consline/configs/12365auto_complaint.cfg'
    A = getConfigFromConfigfile(file_path)
    pprint(A)


